<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button class="main">click</button>
    <script>
        const main = document.querySelector(".main");
        for (const link of document.querySelectorAll("nav > a")) {
        link.addEventListener("click", e => {
            e.preventDefault();

            import('/modules/my-module.js')
            .then(module => {
                module.loadPageInto(main);
            })
            .catch(err => {
                main.textContent = err.message;
            });
        });
        }
    </script>
</body>
</html>